filename = 'birthday.txt'
try:
    file = open(filename,'r')
except FileNotFoundError:
    print(filename,'文件不存在')
else:
    print(filename,'文件有', len(file.readlines()), '行')
    file.close()

filename = 'integer.txt'
try:
    file = open(filename, 'a')
    data = int(input('请输入一个整数: '))
    file.write(str(data))
except Exception as e:
    print(e)
finally:
    print('关闭文件')
    file.close()